package com.jxsd.edu.cn.struts2.serviceImpl;

import java.util.List;

import com.jxsd.edu.cn.struts2.dao.CatagoryDao;
import com.jxsd.edu.cn.struts2.dao.ReplyDao;
import com.jxsd.edu.cn.struts2.dao.TopicDao;
import com.jxsd.edu.cn.struts2.daoImpl.CatagoryDaoImpl;
import com.jxsd.edu.cn.struts2.daoImpl.ReplyDaoImpl;
import com.jxsd.edu.cn.struts2.daoImpl.TopicDaoImpl;
import com.jxsd.edu.cn.struts2.models.Category;
import com.jxsd.edu.cn.struts2.models.Reply;
import com.jxsd.edu.cn.struts2.models.Topic;
import com.jxsd.edu.cn.struts2.services.TopicService;
import com.jxsd.edu.cn.tools.Page;
import com.jxsd.edu.cn.tools.PageBean;

public class TopicServiceImpl implements TopicService 
{
   
	@Override
	public List<Category> getAllCatagory() 
	{
	    CatagoryDao   cataDao=new  CatagoryDaoImpl();
	    List<Category>    list=cataDao.getCatagories();
		return    list;
	}

	@Override
	public  Page<Topic>   getPageTopics(PageBean<Topic>  pagebean,String  smallId,String  cityName)
	{
		TopicDao  topicDao=new  TopicDaoImpl();
//		System.out.println("TopicServiceImpl:smallId:"+smallId);
//		System.out.println("TopicServiceImpl:cityName:"+cityName);
		Page<Topic>   page=topicDao.getPageTopics(pagebean, smallId, cityName);
		return page;
	}

	@Override
	public  Page<Topic>   getAllTopices(PageBean<Topic>   pagebean,String  smallId)
	{
		TopicDao  topicDao=new  TopicDaoImpl();
		Page<Topic>  page=topicDao.getAllTopices(pagebean, smallId);
		return page;
	}

	@Override
	public void addTopic(Topic topic) {
		TopicDao  topicDao=new  TopicDaoImpl();
		topicDao.addTopic(topic);
	}

	@Override
	public void deleteTopic(String topicId) {
		TopicDao  topicDao=new  TopicDaoImpl();
		topicDao.deleteTopic(topicId);
	}

	@Override
	public Page<Topic> getPersonTopic(PageBean<Topic> pagebean,String userId) {
		TopicDao  topicDao=new  TopicDaoImpl();
		Page<Topic>  page=null;
		page=topicDao.getPersonTopic(pagebean, userId);
		return page;
	}

	@Override
	public Topic getTopic(String topicId)
	{
		//获取帖子的基本内容
		TopicDao  topicDao=new  TopicDaoImpl();
		Topic  topic=topicDao.getTopic(topicId);
		//获取回复贴的内容
		ReplyDao  replyDao=new  ReplyDaoImpl();
		List<Reply>  list=replyDao.getReplies(Integer.valueOf(topicId));
		
		topic.setList(list);
		return topic;
	}

	@Override
	public List<Topic> queryNewlyTopic(String cityName) {
		TopicDao  topicDao=new  TopicDaoImpl();
		return topicDao.queryNewlyTopic(cityName);
	}
    
}
